package com.rc.common.util;

import com.rc.common.constant.Code;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * 返回结果包装类
 * @param <T>
 * @author sym
 */
@Data
@AllArgsConstructor
public class R<T> {
    //返回码
    private final int code;

    //返回信息
    private final String msg;

    //返回数据
    private final T data;

    public static <T> R<T> success(T data){
        return new R(Code.OK.getCode(), Code.OK.getMsg(),data);
    }

    public static <T> R success(){
        return success(null);
    }


    public static <T> R<T> fail(Code statusCode){
        return fail(statusCode.getCode(),statusCode.getMsg());
    }

    public static <T> R<T> fail(Integer code ,String msg){
        R r = new R(code,msg,null);
        return r;
    }

}
